<template>
	<view class='page_cont' v-if="info">
		<view class='teach_desc'>
			<view class='name_wrap'>
				<view class='name'>{{info.accountProfile.nickName||info.accountProfile.userName}}</view>
				<view class='point'>
					{{info.accountProfile.birthday?info.accountProfile.age+'岁 · ':''}}
					{{info.accountProfile.sex==1?'男':'女'}} · {{info.accountProfile.educationName?info.accountProfile.educationName+' · ':''}}
					{{info.accountProfile.joinWorkTime?(info.accountProfile.workYear>0?info.accountProfile.workYear+'年':'1年内')+'工作经验':''}}
				</view>
			</view>
			<image class='avatar' :src="info.accountProfile.avatar||'/static/icon27.png'" mode="aspectFill"></image>
		</view>
		<view class='job_inten' v-if="info.jobIntention">
			<view class='title'>求职意向</view>
			<view class='text'>{{info.jobIntention.jobWantedName}}</view>
		</view>
		<view class='job_want' v-if="info.jobIntention">
			<view class='title_wrap'>
				<view class='title'>{{info.jobIntention.positionChildName||info.jobIntention.positionName}}</view>
				<view class='point'>
					<view class='item'>{{info.jobIntention.hierarchyName}}</view>
					<view class='item'>{{info.jobIntention.teacherModeName}}</view>
				</view>
			</view>
			<view class='desc_wrap'>
				<view class='desc'>
					<view class='item'>
						<image class='icon' src="/static/icon28.png"></image>
						<view class='text'>{{info.jobIntention.salary}}</view>
					</view>
					<view class='item'>
						<image class='icon' src="/static/icon29.png"></image>
						<view class='text'>{{info.jobIntention.workNature==1?'全职':'兼职'}}</view>
					</view>
					<view class='item' v-if="info.jobIntention.startTimeName">
						<image class='icon' src="/static/icon30.png"></image>
						<view class='text'>{{info.jobIntention.startTimeName}}</view>
					</view>
				</view>
				<view class='city' v-if="info.jobIntention.citys">
					<image class='icon' src="/static/icon31.png"></image>
					<view class="text">
						<scroll-view class='scroll' scroll-x="true" scroll-with-animation="true">{{info.jobIntention.citys}}</scroll-view>
					</view>
				</view>
			</view>
			<view class='welf' v-if="info.jobIntention.welfareNames.length>0">
				<view class='title'>期望福利</view>
				<view class='job_label_box'>
					<scroll-view class='scroll_label' scroll-with-animation="true" scroll-x="true">
						<view class='label' v-for="(item,index) in info.jobIntention.welfareNames" :key="index">{{item}}</view>
					</scroll-view>
				</view>
				<view class='welf_text' v-if="info.jobIntention.welfareDetail.length>0">
					<view class='text' v-for="(item,index) in info.jobIntention.welfareDetail" :key="index">{{item}}</view>
				</view>
			</view>
		</view>
		<view class='view_wrap'>
			<view class='title'>教育经历<view class='line'></view></view>
			<view class='view_list' v-if='info.experiences.length>0'>
				<view class='item' v-for="(item,index) in info.experiences" :key="index">
					<view class='title_wrap'>
						<view class='name'>{{item.schoolName}}</view>
						<view class='time'>{{item.start}}-{{item.end}}</view>
					</view>
					<view class="text">{{item.educationName}}-{{item.majorName}}</view>
				</view>
			</view>
		</view>
		<view class='view_wrap'>
			<view class='title'>工作经历<view class='line'></view></view>
			<view class='view_list' v-if='info.works.length>0'>
				<view class='item' v-for="(item,index) in info.works" :key="index">
					<view class='title_wrap'>
						<view class='name'>{{item.businessName}}</view>
						<view class='time'>{{item.start}}-{{item.end}}</view>
					</view>
					<view class="text">{{item.positionName}}</view>
					<view class='desc' v-if="item.workDescribe">
						<view class='desc_item' v-for="(itm,index) in item.workDescribe" :key="index">{{itm}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class='footer'>
			<view class='coll_wrap' @click="coll_teacher()">
				<view class='icon_box'><image class='icon' :src="info.collection?'/static/icon19.png':'/static/icon18.png'"></image></view>
				<view class='text'>{{info.collection?'已收藏':'收藏'}}</view>
			</view>
			<view class='cast_btn' @click='call_phone(info.accountProfile.phone)' v-if="status==3||status==4">联系电话{{info.accountProfile.phone?info.accountProfile.phone:''}}</view>
			<view class='cast_btn' @click='open_pop()' v-else>邀请老师投递简历</view>
		</view>
		<pickerPop 
			:showMask="show_mask"
			:showIndex="show_index"
			:title="title"
			:pickers="pickers"
			:value="value"
			@closeMask="close_mask"
			@pickerChange="picker_change"
			@confirmValue="confirm_value"
		>
		</pickerPop>
		<view class="mask" @touchmove.stop.prevent="moveHandle" v-show="show_pop">
			<view class='pop'>
				<view class="title">温馨提示</view>
				<view class='point'>目前你还没有发布招聘职位暂不能邀请老师，可以完善职位要求，再来邀请老师哦</view>
				<view class='btn_wrap'>
					<view class='btn' @click="close_pop()">取消</view>
					<view class='btn' @click="nav_go()">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import home from '../../api/home.js'
	import config from '../../api/config.js'
	import util from "../../utils/util.js"
	import PickerPop from "../../components/pickerPop.vue"
	export default{
		data(){
			return{
				id: '',
				status: '',
				info: '',
				show_mask: false,
				pickers: [],
				value: [0],
				title: '',
				show_index: '',
				show_pop: false,
				userinfo: ''
			}
		},
		onLoad(options) {
			this.id=options.id;
			if(options.status){
				this.status=options.status
			}
			this.userinfo=uni.getStorageSync("userIdentity");
			//
			this.get_teacher_detail(options.id)
			this.get_job_bymech();
		},
		methods:{
			// 收藏
			coll_teacher(){
				if(this.info.collection){
					this.cancel_coll();
				}else{
					this.create_token();
				}
			},
			// 邀请
			open_pop(){
				if(this.status==2){
					util.page_show_toast("您已邀请过当前老师",2000)
					return false;
				}
				// if(this.status==3){
				// 	util.page_show_toast("当前老师已投递过简历",2000)
				// 	return false;
				// }
				if(this.pickers&&this.pickers.length>0){
					this.show_index=1;
					this.title='邀请职位';
					this.show_mask=true;
				}else{
					this.show_pop=true;
				}
			},
			// 联系
			call_phone(phone){
				if(phone){
					uni.makePhoneCall({
						phoneNumber: phone,
						success() {},
						fail() {}
					})
				}else{
					util.page_show_toast("暂未提供联系电话",1500)
				}
			},
			// 关闭选择框
			close_mask(){
				this.show_mask=false;
			},
			// 选择
			picker_change(res){
				this.value=res;
			},
			// 确认
			confirm_value(){
				//
				this.unit_invitation();
			},
			// 禁止触摸穿透
			moveHandle(){},
			// 关闭弹窗
			close_pop(){
				this.show_pop=false;
			},
			// 跳转
			nav_go(){
				uni.navigateTo({
					url: '../../mypage/jobMent/jobMent'
				})
			},
			// 详情
			get_teacher_detail(id){
				uni.showLoading({})
				var params={
					"id": id,
					"type": this.status==2?1:this.status==3?2:''
				}
				home.get_teacher_detail(params).then(res=>{
					uni.hideLoading()
					var info=res.data.data;
					if(info.accountProfile){
						info.accountProfile.age=info.accountProfile.birthday?new Date().getFullYear()-new Date(info.accountProfile.birthday).getFullYear():'';
						info.accountProfile.workYear=info.accountProfile.joinWorkTime?new Date().getFullYear()-new Date(info.accountProfile.joinWorkTime).getFullYear():'';
					}
					if(info.jobIntention){
						var arr=[],city='',
							arr1=info.jobIntention.intentionProvinceName?info.jobIntention.intentionProvinceName.split(","):[],
							arr2=info.jobIntention.intentionCityName?info.jobIntention.intentionCityName.split(","):[],
							arr3=info.jobIntention.intentionRegionName?info.jobIntention.intentionRegionName.split(","):[];
						arr1.forEach((item,index)=>{
							if(arr1[index]==arr2[index]){
								city=arr1[index]
							}else{
								city=arr1[index]+'-'+arr2[index]
							}
							if(arr3[index]!=0&&arr3[index]){
								city=city+'-'+arr3[index]
							}
							arr.push(city)
						})
						arr=arr.filter(function (s) {
								return s && s.trim();
							});
						var welfarr=info.jobIntention.welfareDetail?
							(info.jobIntention.welfareDetail.indexOf("\n")>-1?
							info.jobIntention.welfareDetail.split("\n"):
							info.jobIntention.welfareDetail.indexOf("<br />")>-1?
							info.jobIntention.welfareDetail.split("<br />"):
							info.jobIntention.welfareDetail.split("<br/>")>-1?
							info.jobIntention.welfareDetail.split("<br/>"):[]):[];
						info.jobIntention.welfareDetail=welfarr.filter(function (s) {
								return s && s.trim();
							});
						info.jobIntention.citys=arr.join(",");
						info.jobIntention.welfareNames=info.jobIntention.welfareNames?info.jobIntention.welfareNames.split(","):'';
						info.jobIntention.salary = info.jobIntention.salaryMin==0||!info.jobIntention.salaryMin?"面议":`${info.jobIntention.salaryMin/1000}-${info.jobIntention.salaryMax/1000}k/月`
					}
					info.experiences.forEach((item)=>{
						item.start=util.formatTime1(new Date(item.admissionTime),2);
						item.end=util.formatTime1(new Date(item.graduationTime),2);
					})
					info.works.forEach((item)=>{
						item.start=util.formatTime1(new Date(item.entryTime),2);
						item.end=util.formatTime1(new Date(item.quitTime),2);
						var work=item.workDescribe?item.workDescribe.replace(/&nbsp;/ig,""):'';
						var workarr=work?(work.indexOf("\n")>-1?
							work.split("\n"):
							work.indexOf("<br />")>-1?
							work.split("<br />"):
							work.indexOf("<br/>")>-1?
							work.split("<br/>"):[]):[];
						item.workDescribe=workarr.filter(function (s) {
								return s && s.trim();
							});
					})
					this.info=info;
					uni.setNavigationBarTitle({
					    title: (info.accountProfile.nickName?info.accountProfile.nickName:info.accountProfile.userName)+'的简历'
					});
				})
			},
			// 防重复提交幂等token
			create_token(){
				config.create_token().then(res=>{
					this.add_coll(res.data.data);
				})
			},
			// 收藏
			add_coll(x_token){
				var params={
					"targetId": this.info.accountProfile.id,
					"targetType": 2
				}
				home.add_coll(params,x_token).then(res=>{
					this.get_teacher_detail(this.id);
					util.page_show_toast("收藏成功",1500);
				})
			},
			// 取消收藏
			cancel_coll(){
				var params={
					"id": this.info.collection.id
				}
				home.cancel_coll(params).then(res=>{
					this.get_teacher_detail(this.id);
					util.page_show_toast("取消收藏成功",1500);
					if(this.status==4){
						var pages = getCurrentPages();
						var prevPage = pages[pages.length - 2];
						prevPage.$vm.refresh=true;
					}
				})
			},
			// 邀请职位
			get_job_bymech(){
				home.get_job_bymech().then(res=>{
					var info=res.data.data;
					this.pickers=info;
				})
			},
			// 邀请
			unit_invitation(){
				var pickers=this.pickers,index=this.value[0];
				var params={
					"positionInfoId": pickers[index].id,
					"positionInfoName": pickers[index].name,
					"userProfileId": this.info.accountProfile.id,
					"status": 1,
					"type": 1,
					"businessLogo": pickers[index].businessLogo,
					"businessName": pickers[index].businessName,
					"receiverId": this.info.accountProfile.userId,
					"receiverAvatar": this.info.accountProfile.avatar,
					"receiverName": this.info.accountProfile.nickName,
					"receiverPhone": this.info.accountProfile.phone,
					"senderAvatar": this.userinfo.businessLogo,
					"senderName": this.userinfo.businessName,
					"senderPhone": this.userinfo.principalPhone
				}
				home.unit_invitation(params).then(res=>{
					util.page_show_toast("邀请成功",2000);
					this.close_mask()
				})
			},
		},
		components:{
			pickerPop: PickerPop
		}
	}
</script>

<style lang="scss">
	.page_cont{
		padding: 16rpx 32rpx 144rpx 32rpx;
		.teach_desc{
			padding-bottom: 40rpx;
			border-bottom: 2rpx solid #F7F9FB;
			display: flex;
			flex-direction: row;
			.name_wrap{
				flex: 1;
				margin-right: 16rpx;
				.name{
					text-align: left;
					height: 66rpx;
					font-size: 48rpx;
					font-weight: 600;
					line-height: 66rpx;
					color: #3F4A58;
					margin-bottom: 10rpx;
				}
				.point{
					text-align: left;
					height: 40rpx;
					font-size: 28rpx;
					font-weight: 400;
					line-height: 40rpx;
					color: #798594;
				}
			}
			.avatar{
				width: 116rpx;
				height: 116rpx;
				border-radius: 50%;
			}
		}
		.job_inten{
			padding: 40rpx 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			border-bottom: 2rpx solid #F7F9FB;
			.title{
				flex: 1;
				text-align: left;
				height: 42rpx;
				font-size: 30rpx;
				font-weight: 600;
				line-height: 42rpx;
				color: #3F4A58;
			}
			.text{
				height: 34rpx;
				font-size: 24rpx;
				font-weight: 400;
				line-height: 34rpx;
				color: #798594;
			}
		}
		.job_want{
			padding: 40rpx 0 48rpx 0;
			border-bottom: 2rpx solid #F7F9FB;
			.title_wrap{
				display: flex;
				flex-direction: row;
				align-items: center;
				.title{
					flex: 1;
					text-align: left;
					height: 42rpx;
					font-size: 30rpx;
					font-weight: 600;
					line-height: 42rpx;
					color: #3F4A58;
				}
				.point{
					display: flex;
					flex-direction: row;
					.item{
						padding: 0 16rpx;
						height: 42rpx;
						line-height: 42rpx;
						background: rgba(91,144,255,0.11);
						border-radius: 8rpx;
						font-size: 24rpx;
						font-weight: 400;
						color: #5B90FF;
						margin-right: 16rpx;
					}
				}
			}
			.desc_wrap{
				margin-top: 40rpx;
				.desc{
					display: flex;
					flex-direction: row;
					margin-bottom: 24rpx;
					.item{
						margin-right: 48rpx;
						display: flex;
						flex-direction: row;
						align-items: center;
						&:last-child{
							margin-right: 0;
						}
						.icon{
							width: 40rpx;
							height: 40rpx;
							margin-right: 8rpx;
						}
						.text{
							height: 40rpx;
							font-size: 28rpx;
							font-weight: 400;
							line-height: 40rpx;
							color: #798594;
						}
					}
				}
				.city{
					display: flex;
					flex-direction: row;
					align-items: center;
					.icon{
						width: 40rpx;
						height: 40rpx;
						margin-right: 8rpx;
					}
					.text{
						flex: 1;
						width: 0;
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						line-height: 40rpx;
						color: #798594;
						overflow: hidden;
					}
					.scroll{
						width: 100%;
						height: 54rpx;
						line-height: 40rpx;
						overflow: hide;
						white-space: nowrap;
					}
				}
			}
			.welf{
				width: 100%;
				margin-top: 30rpx;
				.title{
					text-align: left;
					height: 34rpx;
					font-size: 30rpx;
					font-weight: 600;
					line-height: 34rpx;
					color: #3F4A58;
					margin-bottom: 24rpx;
				}
				.job_label_box{
					width: 100%;
					overflow: hidden;
					white-space: nowrap;
					height: 48rpx;
					.scroll_label{
						width: 100%;
						height: 60rpx;
						line-height: 40rpx;
						overflow: hidden;
						.label{
							display: inline-block;
							background: #F6F7F9;
							height: 48rpx;
							line-height: 48rpx;
							padding: 0 16rpx;
							font-size: 24rpx;
							font-weight: 400;
							color:rgba(146,155,167,1);
							border-radius: 8rpx;
							margin-right: 16rpx;
						}
					}
				}
				.welf_text{
					width: 100%;
					margin-top: 24rpx;
					.text{
						font-size: 28rpx;
						font-weight: 400;
						line-height: 42rpx;
						color: #798594;
						margin-bottom: 16rpx;
						&:last-child{
							margin-bottom: 0;
						}
					}
				}
			}
		}
		.view_wrap{
			padding: 48rpx 0;
			border-bottom: 2rpx solid #F7F9FB;
			.title{
				position: relative;
				height: 50rpx;
				font-size: 36rpx;
				font-weight: 600;
				line-height: 50rpx;
				color: #3F4A58;
				.line{
					position: absolute;
					top: 10rpx;
					left: -32rpx;
					width: 8rpx;
					height: 32rpx;
					background: #5B90FF;
				}
			}
			.view_list{
				width: 100%;
				margin-top: 40rpx;
				.item{
					width: 100%;
					margin-bottom: 40rpx;
					&:last-child{
						margin-bottom: 0;
					}
					.title_wrap{
						display: flex;
						flex-direction: row;
						margin-bottom: 6rpx;
						.name{
							flex: 1;
							font-size: 30rpx;
							font-weight: 600;
							line-height: 42rpx;
							color: #3F4A58;
							overflow : hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 2;
							-webkit-box-orient: vertical;
							margin-right: 16rpx;
						}
						.time{
							margin-top: 4rpx;
							height: 34rpx;
							font-size: 24rpx;
							font-weight: 400;
							line-height: 34rpx;
							color: rgba(121,133,148,0.5);
						}
					}
					.text{
						height: 34rpx;
						font-size: 24rpx;
						font-weight: 400;
						line-height: 34rpx;
						color: #929BA7;
					}
					.desc{
						margin-top: 24rpx;
						.desc_item{
							font-size: 28rpx;
							font-weight: 400;
							line-height: 42rpx;
							color: #798594;
						}
					}
				}
			}
		}
		.footer{
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			width: 100%;
			box-sizing: border-box;
			padding: 28rpx 32rpx 26rpx 48rpx;
			z-index: 200;
			border-top: 2rpx solid #F6F7F9;
			display: flex;
			flex-direction: row;
			background: #fff;
			.coll_wrap{
				padding-top: 6rpx;
				margin-right: 42rpx;
				width: 66rpx;
				.icon_box{
					width: 48rpx;
					height: 48rpx;
					margin: 0 auto;
					.icon{
						width: 100%;
						height: 100%;
					}
				}
				.text{
					text-align: center;
					height: 32rpx;
					font-size: 22rpx;
					font-weight: 400;
					line-height: 32rpx;
					color: #929BA7;
				}
			}
			.cast_btn{
				flex: 1;
				text-align: center;
				height: 90rpx;
				line-height: 90rpx;
				background: #5B90FF;
				border-radius: 8px;
				color: #fff;
				font-size: 30rpx;
				font-weight: 400;
			}
		}
		.pop{
			width: 530rpx;
			/* #ifdef MP-WEIXIN||APP-PLUS */
			margin: 304rpx auto 0 auto;
			/* #endif */
			/* #ifdef H5 */
			margin: 200rpx auto 0 auto;
			/* #endif */
			background: #fff;
			border-radius: 16rpx;
			padding: 32rpx 32rpx 46rpx 32rpx;
			.title{
				text-align: left;
				height: 44rpx;
				font-size: 32rpx;
				font-weight: 600;
				line-height: 44rpx;
				color: #666666;
			}
			.point{
				padding: 40rpx 28rpx 58rpx 28rpx;
				font-size: 36rpx;
				font-weight: 600;
				line-height: 50rpx;
				color: #3F4A58;
			}
			.btn_wrap{
				padding: 0 16rpx;
				display: flex;
				flex-direction: row;
				.btn{
					flex: 1;
					height: 88rpx;
					text-align: center;
					line-height: 88rpx;
					font-size: 30rpx;
					font-weight: 400;
					border-radius: 16rpx;
					&:first-child{
						background: rgba(146,155,167,0.15);
						color: #798594;
						margin-right: 38rpx;
					}
					&:last-child{
						background: #5B90FF;
						color: #fff;
					}
				}
			}
		}
	}
</style>
